<?php
declare(strict_types=1);

namespace App\ZxAdmin\Content;

use App\Controller;
use Field\SysPagesConst;
use Field\SysPagesColumns;
use Field\SysPagesRow;

// hook controller_zx_admin_content_pages_use.php

/**
 * @title   单页管理
 * @auth    true
 * @login   true
 * @menu    true
 * @component   vlist/index.vue
 * @icon    el-icon-tickets
 * @active  true
 * @affix   false
 * @rank    99
 */
class Pages extends Controller
{
    // hook controller_zx_admin_content_pages_public_start.php



    // hook controller_zx_admin_content_pages_public_end.php

    /**
     * @title  下发配置
     * @rank    0
     */
    public function action_Conf_PUT()
    {
        // hook controller_zx_admin_content_pages_conf_start.php
        $conf=['pageSizes'=>[10,20,25,50,100,500,1000,10000],'hidePagination'=>0,'TreeData'=>0,'hideDo'=>0,'hideRefresh'=>1,'add'=>1,'enable'=>1,'disable'=>1,'delete'=>1,'import'=>0,'export'=>0,'chartRange'=>0,'copy'=>1,'pageSize'=>'10','Local'=>0];
        $Columns = [['label'=>'操作','type'=>'button','options'=>[['Do'=>'Custom','Type'=>'success','value'=>'','Name'=>'嘿嘿','multiple'=>0,'Dict'=>'OneBizCode','apiObjRemote'=>'zxadmin/users/role/conf'],['Do'=>'Custom','Type'=>'danger','value'=>'','Name'=>'呵呵','do'=>'Custom','apiObjRemote'=>'zxadmin/content/articles/add']]],['table'=>'SysPages','prop'=>'PageID','label'=>'单页ID','hidden'=>1,'search'=>0,'add'=>0,'edit'=>1,'field'=>0,'sortable'=>1,'batch'=>0,'width'=>'80'],['table'=>'SysPages','prop'=>'CateID','label'=>'分类ID','hidden'=>0,'search'=>0,'add'=>0,'edit'=>0,'field'=>1,'sortable'=>0,'batch'=>1,'width'=>80,'type'=>'select','apiObjRemote'=>'zxadmin/users/index/option','editable'=>0],['table'=>'SysPages','prop'=>'Title','label'=>'标题','hidden'=>0,'search'=>1,'add'=>1,'edit'=>1,'field'=>1,'sortable'=>0,'batch'=>0,'width'=>100,'type'=>'input','editable'=>1],['table'=>'SysPages','prop'=>'AttachID','label'=>'附件ID','hidden'=>0,'search'=>0,'add'=>0,'edit'=>0,'field'=>1,'sortable'=>0,'batch'=>0,'width'=>80,'type'=>'image','disabled'=>1,'editable'=>1],['table'=>'SysPages','prop'=>'UserID','label'=>'会员编号','hidden'=>0,'search'=>0,'add'=>0,'edit'=>0,'field'=>1,'sortable'=>0,'width'=>80,'batch'=>1,'type'=>'input','editable'=>0],['table'=>'SysPages','prop'=>'CreateAt','label'=>'创建日期','hidden'=>0,'search'=>1,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>1,'batch'=>0,'width'=>'130','type'=>'date'],['table'=>'SysPages','prop'=>'UpdateAt','label'=>'最后修改','hidden'=>0,'search'=>1,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>1,'batch'=>0,'width'=>'130','type'=>'date'],['table'=>'SysPages','prop'=>'Status','label'=>'状态','hidden'=>0,'search'=>1,'add'=>0,'edit'=>0,'field'=>1,'sortable'=>0,'width'=>80,'batch'=>0,'type'=>'dict','dict'=>'Status','editable'=>1],['table'=>'SysPages','prop'=>'IsRecom','label'=>'推荐','hidden'=>0,'search'=>1,'add'=>0,'edit'=>0,'field'=>1,'sortable'=>0,'width'=>80,'batch'=>0,'type'=>'dict','dict'=>'On','editable'=>1],['table'=>'SysPages','prop'=>'Views','label'=>'访问','hidden'=>0,'search'=>0,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>1,'width'=>'80'],['table'=>'SysPages','prop'=>'Zan','label'=>'赞','hidden'=>0,'search'=>0,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>1,'width'=>'80'],['table'=>'SysPages','prop'=>'Cai','label'=>'踩','hidden'=>0,'search'=>0,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>1,'width'=>'80'],['table'=>'SysPages','prop'=>'Rank','label'=>'排序','hidden'=>0,'search'=>0,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>1,'width'=>'80']];
        $Filter = [['table'=>'SysPages','prop'=>'Title','label'=>'标题','hidden'=>0,'search'=>1,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>0,'mode'=>'LI','component'=>'input','span'=>4],['table'=>'SysPages','prop'=>'CreateAt','label'=>'创建日期','hidden'=>1,'search'=>1,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>0,'mode'=>'><','component'=>'date','type'=>'daterange','span'=>4,'valueFormat'=>'YYYY-MM-DD'],['table'=>'SysPages','prop'=>'UpdateAt','label'=>'更新日期','hidden'=>1,'search'=>1,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>0,'mode'=>'><','component'=>'date','type'=>'daterange','span'=>4,'valueFormat'=>'YYYY-MM-DD'],['table'=>'SysPages','prop'=>'Status','label'=>'状态','hidden'=>0,'search'=>1,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>0,'mode'=>'=','component'=>'radioGroup','dict'=>'Status','span'=>4],['table'=>'SysPages','prop'=>'IsRecom','label'=>'推荐','hidden'=>0,'search'=>1,'add'=>0,'edit'=>0,'field'=>0,'sortable'=>0,'mode'=>'=','component'=>'radioGroup','dict'=>'On','span'=>4]];
        $Tools = [['Do'=>'Dict','Type'=>'primary','value'=>[],'Name'=>'哈哈','do'=>'dict','dict'=>'Editor','multiple'=>1,'Dict'=>'OneBizCode','Field'=>'IsRecom'],['Do'=>'Custom','Type'=>'success','value'=>'','Name'=>'呵呵','do'=>'custom','apiObjRemote'=>'zxadmin/content/cate/add','multiple'=>0]];

        // hook controller_zx_admin_content_pages_conf_end.php
        $this->response('0000', ['Conf' =>$conf, 'Filter' => $Filter, 'Tools' =>$Tools, 'Columns' => $Columns]);
    }

    /**
     * @title   下发列表数据
     * @rank    73
     */
    public function action_Index_GET()
    {
        // hook controller_zx_admin_content_pages_index_start.php
        $page = $this->request->param('page', 0);
        $size = $this->request->param('limit', 0);
        $field = $this->request->param('field', 'PageID');
        $sort = $this->request->param('sort', -1);
        $order = [];
        !empty($field) && $order[$field] = $sort == 'asc' ? -1 : 1;
        $cond = [];
        $Title=$this->request->param('Title',);
		!empty($Title) && $cond['Title']['LI']=$Title;
		$CreateAt=$this->request->param('CreateAt',[]);
		!empty($CreateAt) && $cond['CreateAt']['><']=[$CreateAt[0].' 00:00:00',$CreateAt[1].' 23:59:59'];
		$UpdateAt=$this->request->param('UpdateAt',[]);
		!empty($UpdateAt) && $cond['UpdateAt']['><']=[$UpdateAt[0].' 00:00:00',$UpdateAt[1].' 23:59:59'];
		$Status=$this->request->param('Status',-1);
		$Status!=-1 && $cond['Status']=$Status;
		$IsRecom=$this->request->param('IsRecom',-1);
		$IsRecom!=-1 && $cond['IsRecom']=$IsRecom;
        $data = $this->SysPages->GetList($cond, $order, $page, $size);
        
        foreach ($data['data'] as &$row) {
            
            //unset($row['PassWord'],$row['Salt']);
        }

        // hook controller_zx_admin_content_pages_index_end.php
        $this->response('0000', $data);
    }
    
    /**
     * @title   新增配置
     * @rank    72
     */
    public function action_Add_PUT()
    {
        // hook controller_zx_admin_content_pages_add_put_start.php
        $AddForm = [['table'=>'SysPages','prop'=>'Title','label'=>'标题','hidden'=>0,'search'=>1,'add'=>1,'edit'=>0,'field'=>0,'sortable'=>0,'component'=>'input','span'=>24,'required'=>0]];
        // hook controller_zx_admin_content_pages_add_put_end.php
        $this->response('0000', ['data' => $AddForm]);
    }

    /**
     * @title   新增提交
     * @rank    71
     */
    public function action_Add_POST()
    {
        // hook controller_zx_admin_content_pages_add_post_start.php
        $data = [];
        $data['Title']=$this->request->param('Title',);
        $r = $this->SysPages->insert($data);
        // make addformpost SysPages ZxAdmin\Content
        // hook controller_zx_admin_content_pages_add_post_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r],$r?'操作成功':'操作失败');
    }
    
    
    
    /**
     * @title   编辑字段
     * @rank    60
     */
    public function action_Field_POST()
    {
        // hook controller_zx_admin_content_pages_field_post_start.php
        $cond = [];
        $cond['PageID']=$this->request->param('PageID',0);
        $field = $this->request->param('field', '');
        $value = $this->request->param('value', '');
        $this->CheckEmpty([$field,...$cond], ['待修改数据','待修改字段']);
        $field_fields = ['CateID','Title','AttachID','UserID','Status','IsRecom'];
        $tmp_field=rtrim($field,'+-*/=');
        !in_array($tmp_field, $field_fields, true) && $this->response('0001', [], '字段不允许修改');
        !in_array($tmp_field, SysPagesConst::fields, true) && $this->response('0001', [], '字段不允许修改');
        $update = [];
        switch ($tmp_field) {
        case 'CateID':
         case 'AttachID':
         case 'UserID':
         case 'Status':
         case 'IsRecom':
             $update[$field] = intval($value);
            break;
         case 'Title':
             $update[$field] = $value;
            break;
        }
        $r = !empty($update) ? $this->SysPages->update($cond, $update) : false;
        // hook controller_zx_admin_content_pages_field_post_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r],$r?'操作成功':'操作失败');
    }
    
    
    /**
     * @title   批量编辑字段
     * @rank    60
     */
    public function action_Update_POST()
    {
        // hook controller_zx_admin_content_pages_update_post_start.php
        $data = $this->request->param('data', []);
        $cond=[];
        foreach ($data as $row){
            isset($row['PageID']) && $cond['PageID'][]=intval($row['PageID']);
        }
        $field = $this->request->param('field', '');
        $value = $this->request->param('value', '');
        $this->CheckEmpty([$field,...$cond], ['待修改数据','字段']);
        $update_fields = ['CateID','UserID'];
        $tmp_field=rtrim($field,'+-*/=');
        !in_array($tmp_field, $update_fields, true) && $this->response('0001', [], '字段不允许修改');
        !in_array($tmp_field, SysPagesConst::fields, true) && $this->response('0001', [], '字段不允许修改');
        $update = [];
        switch ($tmp_field) {
        case 'CateID':
         case 'UserID':
             $update[$field] = intval($value);
            break;
        }
        $r = !empty($update) ? $this->SysPages->update($cond, $update) : false;
        // hook controller_zx_admin_content_pages_update_post_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r],$r?'操作成功':'操作失败');
    }
    

    
    /**
     * @title   启用
     * @rank    41
     */
    public function action_Enable_POST()
    {
        // hook controller_zx_admin_content_pages_enable_start.php
        $data = $this->request->param('data', []);
        $cond=[];
        foreach ($data as $row){
                isset($row['PageID']) && $cond['PageID'][]=intval($row['PageID']);
        }
        $this->CheckEmpty($cond, ['待修改数据']);
        $r = $this->SysPages->update($cond, [SysPagesConst::Status => 1]);
        // hook controller_zx_admin_content_pages_enable_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r],$r?'操作成功':'操作失败');
    }

    /**
     * @title   禁用
     * @rank    40
     */
    public function action_Disable_POST()
    {
        // hook controller_zx_admin_content_pages_disable_start.php
        $data = $this->request->param('data', []);
        $cond=[];
        foreach ($data as $row){
                isset($row['PageID']) && $cond['PageID'][]=intval($row['PageID']);
        }
        $this->CheckEmpty($cond, ['操作数据为空']);
        $r = $this->SysPages->update($cond, [SysPagesConst::Status => 0]);
        // hook controller_zx_admin_content_pages_disable_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r],$r?'操作成功':'操作失败');
    }
    
    
    /**
     * @title   下拉选择属性
     * @rank    30
     */
    public function action_Option_GET()
    {
        // hook controller_zx_admin_content_pages_option_start.php

        $value = $this->request->param('value');
        $cond = [
            'OptionField'=>['LIKE'=>$value]
        ];
        $order = [];
        $list = $this->SysPages->select($cond, $order, 1, 100);
        $data=[];
        foreach ($list as $row){
            $data[]=[
              'label'=>$row['OptionLabel'],
              'value'=>$row['OptionValue'],
            ];
        }
        // hook controller_zx_admin_content_pages_option_end.php
        $this->response('0000', ['data' => $data]);
    }
    
    
    

      
     /**
      * @title   删除数据
      * @rank    50
      */
    public function action_Index_Delete()
    {
        // hook controller_zx_admin_content_pages_delete_start.php
        $data = $this->request->param('data', []);
        $cond=[];
        foreach ($data as $row){
            isset($row['PageID']) && $cond['PageID'][]=intval($row['PageID']);
        }
        $this->CheckEmpty($cond, ['操作数据为空']);
        $r = $this->SysPages->delete($cond);
        // hook controller_zx_admin_content_pages_delete_end.php
        $this->response($r ? '0000' : '0001', ['data' => $r]);
    }
    
    // hook controller_zx_admin_content_pages_end.php
}

?>